Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • *egen pair_id = group(DIST).

    Hi,

    I have created an id variable for a pair of countries(exporter importer) based on their distance (DIST):

    egen pair_id = group(DIST).

    However, in my base, the distance ISR-JOR is not exactly the same distance JOR-ISR considering all the decimals.

    What can I do?


    exporter importer pair_id year DIST
    ISR JOR 2 1990 114.6373
    ISR JOR 2 1998 114.6373
    ISR JOR 2 1986 114.6373
    ISR JOR 2 1994 114.6373
    ISR JOR 2 2002 114.6373
    ISR JOR 2 2006 114.6373
    JOR ISR 3 2002 114.6373
    JOR ISR 3 1998 114.6373
    JOR ISR 3 2006 114.6373
    JOR ISR 3 1990 114.6373
    JOR ISR 3 1986 114.6373

    Thanks!


  • #2
    This is another way to form pair id's:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str3(exporter importer) byte pair_id int year float DIST
    "ISR" "JOR" 2 1990 114.6373
    "ISR" "JOR" 2 1998 114.6373
    "ISR" "JOR" 2 1986 114.6373
    "ISR" "JOR" 2 1994 114.6373
    "ISR" "JOR" 2 2002 114.6373
    "ISR" "JOR" 2 2006 114.6373
    "JOR" "ISR" 3 2002 114.6373
    "JOR" "ISR" 3 1998 114.6373
    "JOR" "ISR" 3 2006 114.6373
    "JOR" "ISR" 3 1990 114.6373
    "JOR" "ISR" 3 1986 114.6373
    end
    
    gen countrypair = cond(exporter < importer, exporter + " " + importer, importer + " " + exporter)
    egen wanted = group(countrypair)
    list, noobs abbr(14)
    Code:
    . list, noobs abbr(14)
    
      +------------------------------------------------------------------------+
      | exporter   importer   pair_id   year       DIST   countrypair   wanted |
      |------------------------------------------------------------------------|
      |      ISR        JOR         2   1990   114.6373       ISR JOR        1 |
      |      ISR        JOR         2   1998   114.6373       ISR JOR        1 |
      |      ISR        JOR         2   1986   114.6373       ISR JOR        1 |
      |      ISR        JOR         2   1994   114.6373       ISR JOR        1 |
      |      ISR        JOR         2   2002   114.6373       ISR JOR        1 |
      |------------------------------------------------------------------------|
      |      ISR        JOR         2   2006   114.6373       ISR JOR        1 |
      |      JOR        ISR         3   2002   114.6373       ISR JOR        1 |
      |      JOR        ISR         3   1998   114.6373       ISR JOR        1 |
      |      JOR        ISR         3   2006   114.6373       ISR JOR        1 |
      |      JOR        ISR         3   1990   114.6373       ISR JOR        1 |
      |------------------------------------------------------------------------|
      |      JOR        ISR         3   1986   114.6373       ISR JOR        1 |
      +------------------------------------------------------------------------+

    Comment


    • #3
      It works! Thank you!!!! Wouter Wakker

      Comment


      • #4
        See also https://www.stata-journal.com/articl...article=dm0043 for a broader discussion.

        Comment


        • #5
          Thank you Nick Cox !

          Comment

          Working...
          X